package cn.com.shiroservice.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.shiroservice.LoginService;
import cn.com.word.mapper.GetItems;
import cn.com.word.mapper.SysUserMapper;
import cn.com.word.pojo.SysPermission;
import cn.com.word.pojo.SysUser;
import cn.com.word.pojo.SysUserExample;
import cn.com.word.pojo.SysUserExample.Criteria;
@Service
public class LoginServiceImpl implements LoginService {
	@Autowired
	SysUserMapper userMapper;
	@Autowired
	GetItems getItems;
	
	@Override
	public SysUser getUserByUserCode(String userName) {
		SysUserExample example=new SysUserExample();
		Criteria criteria=example.createCriteria();
		criteria.andUsercodeEqualTo(userName);
		List<SysUser> users=userMapper.selectByExample(example);
		if(users.isEmpty()){
			return null;
		}else{
			return users.get(0);
		}
		
	}
	
	@Override
	public List<SysPermission> getSysPermissionByUserCode(String usercode) {
		
		List<SysPermission> sysPermissions=getItems.getItemsByUserCode(usercode);
		System.out.println("菜单个数："+sysPermissions.size());
		return sysPermissions;
	}
	
}
